<?php
defined('SITE_PATH') or exit('No permission resources.');
//if(empty($_SERVER['HTTP_REFERER'])||strpos($_SERVER['HTTP_REFERER'],'3u8.net')===false) exit('非法调用');
require_once APP_PATH.'lib'.DS.'checkCode.class.php';
$code=new checkCode();
if (isset($_GET['l']) && intval($_GET['l'])) $code->code_len = intval($_GET['l']);
if ($code->code_len > 8 || $code->code_len < 2) {
	$code->code_len = 4;
}
if (isset($_GET['s']) && intval($_GET['s'])) $code->font_size = intval($_GET['s']);
if (isset($_GET['w']) && intval($_GET['w'])) $code->width = intval($_GET['w']);
if ($code->width <= 0) {
	$code->width = 130;
}

if (isset($_GET['h']) && intval($_GET['h'])) $code->height = intval($_GET['h']);
if ($code->height <= 0) {
	$code->height = 50;
}
$max_width = $code->code_len * 28;
$max_height = $code->font_size * 2;
if($code->width > $max_width) $code->width = $max_width;
if($code->height > $max_height) $code->height = $max_height;

if (isset($_GET['c']) && trim(urldecode($_GET['c'])) && preg_match('/(^#[a-z0-9]{6}$)/im', trim(urldecode($_GET['c'])))) $code->font_color = trim(urldecode($_GET['c']));
if (isset($_GET['background']) && trim(urldecode($_GET['b'])) && preg_match('/(^#[a-z0-9]{6}$)/im', trim(urldecode($_GET['b'])))) $code->background = trim(urldecode($_GET['b']));
$code->doimage();
$_SESSION['img_code']=$code->get_code();